package com.ftg.learn.chapter04;

/**
 * 电脑类
 *
 * @author kangjx
 * @version 1.0
 * @date 2023/6/10 下午2:42
 */
public class Computer {

    private String player;

    public void setPlayer(String player) {
        this.player = player;
    }

    public String getPlayer() {
        return this.player;
    }

    /**
     * 随机生成1 -3数
     *
     * @return
     */
    private int createNum() {
        return (int) (Math.random() * 3) + 1;
    }

    /**
     * 文本提示了
     *
     * @param i
     * @return
     */
    private String getMessWithNum(int i) {
        switch (i) {
            case 1:
                return "剪子";
            case 2:
                return "石头";
            case 3:
                return "布";
            default:
                return "错了";
        }
    }

    public void winner(Computer c) {
        int otherComputerInt = c.createNum();
        int myselfInt = this.createNum();

        String otherComMess = c.getMessWithNum(otherComputerInt);
        String myselfMess = c.getMessWithNum(myselfInt);

        if (myselfInt == 1 && otherComputerInt == 3) {
            System.out.printf("玩家%s出了一个%s,玩家%s出一个%s,恭喜玩家%s胜出\n", c.getPlayer(), otherComMess, this.getPlayer(), myselfMess, this.getPlayer());
        } else if (myselfInt == 3 && otherComputerInt == 1) {
            System.out.printf("玩家%s出了一个%s,玩家%s出一个%s,恭喜玩家%s胜出\n", c.getPlayer(), otherComMess, this.getPlayer(), myselfMess, c.getPlayer());
        } else if (otherComputerInt > myselfInt) {
            System.out.printf("玩家%s出了一个%s,玩家%s出一个%s,恭喜玩家%s胜出\n", c.getPlayer(), otherComMess, this.getPlayer(), myselfMess, c.getPlayer());
        } else if (myselfInt > otherComputerInt) {
            System.out.printf("玩家%s出了一个%s,玩家%s出一个%s,恭喜玩家%s胜出\n", c.getPlayer(), otherComMess, this.getPlayer(), myselfMess, this.getPlayer());
        } else {
            System.out.printf("玩家%s出了一个%s,玩家%s出一个%s,平局\n", c.getPlayer(), otherComMess, this.getPlayer(), myselfMess);
        }

    }

}
